<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<%@page import="javax.jdo.PersistenceManager"%>
<%@page import="kr.icg.mshtest2.PMF"%>
<%@page import="kr.icg.mshtest2.Mention"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Date"%>
<%@page import="javax.jdo.Query"%>

<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>Hello App Engine</title>

  </head>

  <body style="margin:0px">
  <%
  String sQuery =  request.getParameter("newQuery");
  if(sQuery ==null || sQuery.equals("null"))
	  sQuery = "";
  
  String sSel =  request.getParameter("newQuery");
  if(sSel ==null || sSel.equals("null"))
	  sSel = "1";
  
  Date date = new Date();
  Mention men = new Mention("", "nick3", "test3",(float)33.491,(float)126.53,date);
  PersistenceManager pm = PMF.get().getPersistenceManager();
  //pm.makePersistent(men);
  Query Query = pm.newQuery(Mention.class);
  Query.setFilter("authorEmail == 'choihkil@gmail.com'");
  Query.deletePersistentAll();
  
  %>
  
  	  <div id="query">
  	  <textarea name='result' cols=50 rows=20>
  	<%
  	//&& latitude <= 33.51193) && (longitude >= 126.50724 && longitude <= 126.55513)
	//String query = "select from " + Mention.class.getName() + " order by date desc limit 10";
  	
  	Query query = pm.newQuery(Mention.class);
  	query.setRange(0,10);
  	query.setOrdering("date desc"); 
  	
  	
  	
	List<Mention> Mentions = (List<Mention>) query.execute();
	if (!Mentions.isEmpty()) 
	{
		for (Mention m : Mentions) {
			
			out.println(m.getContent()+" ,"+ m.getAuthorEmail()+".");
		}
		
	}
	else
		out.println("없음");
	pm.close();
%>
  	  
  	  
  	  </textarea>
  	  <br>
  	  <form action = query.jsp method=post>
  	  last query  = <input type='text' style='width:300px;' value=<%=sQuery%> name = 'lastquery'/>
  	  <br>
  	    셀렉트<input type="radio" name='sel' checked value='s'>
  	    인서트<input type="radio" name='sel' value='i' >
  	  <br>
  	  new-query  = <input type='text' style='width:300px;' name = 'newQuery'/>
  	  <input type = submit>
  	  </form>
  	  
  	  
  	  </div>
  </body>
</html>
